package stores

import "jvmgo/ch06/instructions/base"
import "jvmgo/ch06/rtda"

// 把int值存入局部变量表
type ISTORE struct {
    base.Index8Instruction
}

func (self *ISTORE) Execute(frame *rtda.Frame) {
    _istore(frame, uint(self.Index))
}

type ISTORE_0 struct {
    base.NoOperandsInstruction
}

func (self *ISTORE_0) Execute(frame *rtda.Frame) {
    _istore(frame, 0)
}

type ISTORE_1 struct {
    base.NoOperandsInstruction
}

func (self *ISTORE_1) Execute(frame *rtda.Frame) {
    _istore(frame, 1)
}

type ISTORE_2 struct {
    base.NoOperandsInstruction
}

func (self *ISTORE_2) Execute(frame *rtda.Frame) {
    _istore(frame, 2)
}

type ISTORE_3 struct {
    base.NoOperandsInstruction
}

func (self *ISTORE_3) Execute(frame *rtda.Frame) {
    _istore(frame, 3)
}

//从栈帧中的操作数栈中读取指定索引值的数值，然后存入局部变量表
func _istore(frame *rtda.Frame, index uint) {
    val := frame.OperandStack().PopInt()
    frame.LocalVars().SetInt(index, val)
}
